﻿using System.Collections.Generic;
using NServiceBus.Management.Messages.EndpointControl;
using NServiceBus.Management.Messages.Status;

namespace NServiceBus.Management.EndpointExplorer
{
    public class StatusEventHandler: IMessageHandler<StatusEvent>,
                                     IMessageHandler<PingResponse>
    {
        private readonly EndpointExplorerModel model;
        public StatusEventHandler(EndpointExplorerModel model)
        {
            this.model = model;
        }

        public void Handle(StatusEvent message)
        {
            var endpoints = new List<Endpoint>();
            foreach (var endpointStatus in message.CurrentStatus)
            {
                endpoints.Add(new Endpoint
                                  {
                                      Id = endpointStatus.EndpointId,
                                      Name = endpointStatus.EndpointName,
                                      Host = endpointStatus.HostName,
                                      InputAdress = endpointStatus.InputAdress
                                  });
            }
            model.Handle(endpoints);
        }

        public void Handle(PingResponse message)
        {
        }
    }
}
